package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.DataLabelsComponent;
import com.zygh.policeasset.mapper.AuditFlowMapper;
import com.zygh.policeasset.mapper.SettlementMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.ProjectNameType;
import com.zygh.policeasset.pojo.Section;
import com.zygh.policeasset.pojo.Settlement;
import com.zygh.policeasset.pojo.TableType;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.utils.AuditUtil;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/SettlementService.class */
public class SettlementService {
    @Autowired
    SettlementMapper settlementMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowService auditFlowService;

    public List<Project> getProject(Integer userId) {
        List<Project> projectList = this.settlementMapper.getProject(userId);
        List<Project> newProjectList = new ArrayList<>();
        int i = 0;
        while (i < projectList.size()) {
            if (projectList.get(i).getCategory() == 1 && ("未通过".equals(projectList.get(i).getInitialType()) || "未通过".equals(projectList.get(i).getFinalType()))) {
                projectList.remove(i);
                i--;
            }
            System.out.println(projectList.get(i));
            if (projectList.get(i).getCategory() == 2 && ("未通过".equals(projectList.get(i).getFinalType()) || projectList.get(i).getProgress().intValue() < 100)) {
                projectList.remove(i);
                i--;
            }
            i++;
        }
        for (int i2 = 0; i2 < projectList.size(); i2++) {
            if (!newProjectList.contains(projectList.get(i2))) {
                newProjectList.add(projectList.get(i2));
            }
        }
        return newProjectList;
    }

    public List<Section> getAdd(String projectNo, Integer userId) {
        List<Section> sectionList = this.settlementMapper.getAdd(projectNo, userId);
        int i = 0;
        while (i < sectionList.size()) {
            if ("ZN".equals(projectNo.substring(0, 2)) && "未通过".equals(sectionList.get(i).getInitialType())) {
                sectionList.remove(i);
                i--;
            }
            i++;
        }
        return sectionList;
    }

    public List<ProjectNameType> selectBytype() {
        return this.settlementMapper.selectBytype();
    }

    public List<ProjectNameType> findSectionByType(String projectNo) {
        return this.settlementMapper.findSectionByType(projectNo);
    }

    public Integer findCount() {
        return this.settlementMapper.findCount();
    }

    public Integer findAssetsAppCount(Integer userId) {
        return this.settlementMapper.findAssetsAppCount(userId);
    }

    public int add(Settlement settlement) {
        String now = DateUtil.now();
        String flowNo = AuditUtil.getFlowNo(now);
        settlement.setFlowNo(flowNo);
        int settlementId = 0;
        try {
            settlement.setDataLabelsId(DataLabelsComponent.toEnableId);
            this.settlementMapper.add(settlement);
            settlementId = settlement.getId().intValue();
            this.auditFlowService.add(settlement.getUserId(), flowNo, now, TableType.SETTLEMENT.getName(), TableType.SETTLEMENT.getType(), settlement.getProjectNo(), Integer.valueOf(Integer.parseInt(settlement.getSectionId())));
            for (UploadFile uploadFile : settlement.getUploadFileList()) {
                uploadFile.setProjectId(settlementId);
                uploadFile.setProjectName("settlement");
                uploadFile.setCreateDate(DateUtil.now());
                this.uploadFileMapper.add(uploadFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return settlementId;
    }

    public PageInfo findAll(String name, Integer status, Integer companyId, Integer PageNum, Integer PageSize, String time1, String time2, Integer category, Integer userId) {
        PageHelper.startPage(PageNum.intValue(), PageSize.intValue());
        return new PageInfo<>(this.settlementMapper.findAll(name, status, companyId, time1, time2, category, userId));
    }

    public List<Settlement> findByProjectNoPage(String no) {
        return this.settlementMapper.findByProject(no);
    }

    public PageInfo findByStatus(int status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.settlementMapper.findByStatus(status));
    }

    public Settlement selectById(Integer id) {
        return this.settlementMapper.selectById(id);
    }

    public int update(Settlement settlement) {
        return this.settlementMapper.update(settlement);
    }

    public int delete(Integer id) {
        int res = 0;
        try {
            res = this.settlementMapper.delete(id);
            this.uploadFileMapper.delete(id.intValue(), "settlement");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    public Integer updateStatus(int id, int status) {
        return this.settlementMapper.updateStatus(id, status);
    }

    public List<Settlement> toExcel(Integer id, String name, String companyId, String time1, String time2) {
        return this.settlementMapper.toExcel(id, name, companyId, time1, time2);
    }

    public int updateStatusAssets(String assetNewStatus, String projectNo, Integer sectionId) {
        return this.settlementMapper.updateStatusAssets(assetNewStatus, projectNo, sectionId);
    }

    public int updateSPD(String startProvisionDate, String certificateNum, String projectNo, Integer sectionId) {
        return this.settlementMapper.updateSPD(startProvisionDate, certificateNum, projectNo, sectionId);
    }
}